<script lang="ts" setup name="PlanDialog">
import type { Props, Emits } from "./interface";
import { watch, ref } from "vue";
import { useDebounceFn } from "@vueuse/core";
const props = defineProps<Props>();
const emit = defineEmits<Emits>();

const DialogVisible = ref(false); // 显示与隐藏
watch(
  () => props.dialogVisible,
  visible => {
    DialogVisible.value = visible;
    if (!props.dialogVisible) {
      searchVal.value = "";
    }
  }
);

// input 输入数据传送父组件 searchValue
const searchVal = ref("");
const changeSearch = useDebounceFn(() => {
  console.log(searchVal.value);
  emit("emitSearch", searchVal.value);
}, 800);

// 表格选中事件
const selectPlanList = ref<any>([]);
const handleSelectionChange = e => {
  selectPlanList.value = e;
};

// 确认选中
const onselectPlanList = () => {
  emit("emitSelectList", selectPlanList.value);
  emit("changeVisible", false);
};

// 关闭弹框
const handleClose = () => {
  emit("changeVisible", false);
};
</script>

<template>
  <div>
    <el-dialog
      v-model="DialogVisible"
      title="盘点计划列表"
      width="700"
      style="height: 580px; overflow: auto"
      :before-close="handleClose"
    >
      <!-- <div v-for="item in 100" :key="item">{{ item }}</div> -->
      <div style="padding: 20px">
        <el-input v-model="searchVal" @input="changeSearch" size="small" placeholder="请输入单据号" />
      </div>
      <el-table
        ref="planTableRef"
        row-key="orderId"
        :data="planList"
        style="width: 100%; height: 380px"
        @current-change="handleSelectionChange"
        highlight-current-row
        border
      >
        <!-- <el-table-column align="center" type="radio" width="55" /> -->
        <el-table-column align="center" prop="orderNo" label="盘点计划编码" />
        <el-table-column align="center" prop="createTime" label="盘点计划创建时间" />
        <el-table-column align="center" prop="status" label="盘点状态" width="120">
          <template #default="{ row }">
            <span v-if="row.status === 1">待盘点</span>
            <span v-else-if="row.status === 2">盘点中</span>
            <span v-else-if="row.status === 3">待审核</span>
            <span v-else>已完成</span>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="onselectPlanList"> 确定 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped>
::v-deep .el-table__body-wrapper {
  cursor: pointer !important;
}
</style>
